<?php

namespace app\controller;

use app\BaseController;
use app\Log;
use app\model\Order;

class Cgas extends BaseController
{
    public function confirm()
    {
        $log = new Log('/cGas/confirm');
        $params = $this->request->param();
        $data = $this->app->make(\cgas\CGas::class)->notifyData($params);
        if (!empty($data['params']['ticket_num'])) {
            $order = $this->app->make(Order::class)->where('code', $data['params']['ticket_num'])->find();
            if (!empty($order)) {
                $order->state = 2;
                $order->used_time = $data['params']['use_time'];
                $order->save();
            }
        }
        $log->write($data);
        return json($data['data']);
    }

    public function cancel()
    {
        $params = $this->request->param();
        return json($this->app->make(\cgas\CGas::class)->notifyData($params));
    }
}
